<?php

function get_last_question(){
	$cxn = db_connect();
	$query = "SELECT * FROM polls_questions order by date desc limit 1";
	$result = mysqli_query($cxn,$query) or die("Couldn't execute get_last_question");
	return $result;
}

function post_vote($question_id, $answer){
	$cxn = db_connect();
	$query = "UPDATE polls_questions
	SET votes = votes + 1
	WHERE question_id =".$question_id;
	mysqli_query( $cxn, $query );

	$query = "UPDATE polls_answers
	SET votes = votes + 1
	WHERE answer_id =".$answer;
	mysqli_query( $cxn, $query );
}

function get_answers_to_questions($question_id){
	$cxn = db_connect();
	$query = "SELECT * FROM polls_answers where question_id='$question_id'";
	$result = mysqli_query($cxn,$query) or die("Couldn't execute get_answers_to_questions");
	return $result;
}

function get_votes_for_question($question_id){
	$cxn = db_connect();
	$query = "SELECT votes FROM polls_questions where question_id='$question_id'";
	$result = mysqli_query($cxn,$query) or die("Couldn't execute get_votes_for_question");
	return $result;
}

?>